const { Sequelize, Model, INTEGER } = require('sequelize')
const { db } = require('../core/sequelize')
class SignIn extends Model {
    //static关键字静态方法 不用new 可以直接调用
    static async setSignIn(time, userId) {
        // 判断今天是否签到
        let result = await SignIn.findCreateFind({
            // 没有 就插入一条数据
            defaults: {
                signInTime: time,
                userId: userId
            },
            // 查询是否已经签到
            where: {
                sign_in_time: time,
                user_id: userId
            }
        })

        return result[1]

    }
    static async getSignList(userId) {
        // where查询
        const signList = await SignIn.findAll({
            where: {
                userId
            }
        })
        return signList
    }
}
SignIn.init(
    {
        id: {
            type: Sequelize.INTEGER,
            primaryKey: true, //设置主键
            autoIncrement: true,
        },
        signInTime: Sequelize.INTEGER, //类型 字符串
        userId: Sequelize.INTEGER, //类型 字符串
        // createTime: Sequelize.STRING, //类型 字符串
    },
    {
        // underscored: true,
        sequelize: db,
        modelName: 'signIn', timestamps: false
    }
)
module.exports = { SignIn }
